<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 
    栈内存 
        会自动分配内存空间，会自动释放
        存放基本数据类型, 占据固定的大小空间
        (String、Number、Boolean、Undefined、Null)
    
    堆内存
        动态分配内存空间, 内存大小不一定会自动释放
        存放引用数据类型(Object、Array)
        保存在堆内存中，包含引用类型的变量实际上保存的不是变量本身，而是指向该对象的指针
    -->

    <script>
        let srt = " "; // 存放在栈内存
        let arr2 = [99, 88, 77];
        let arr = [0, 1, 2]; // [0, 1, 2]存放在堆内存
        let newArr1 = arr; // 复制内存地址(指针)
        let newArr2 = arr; // 复制内存地址(指针)
        let obj = {
            id: 1
        };
        let newObj = obj; // 复制内存地址(指针)


        newArr2[0] = 999;
        console.log("arr", arr);
        console.log("newArr1", newArr1);
        console.log("newArr2", newArr2);


        newObj.id = 999;
        newObj['name'] = "hy";
        console.log("obj", obj);
        console.log("newObj", newObj);



        let str1 = "我是字符串1";
        let newStr = str1;

        newStr = "我是字符串2";
        console.log("str1", str1);
        console.log("newStr", newStr);
    </script>
</body>

</html>